<template>
  <div class="wp" v-if="CreateMathBoolean">
    <div class="content">
      <!-- 标题 -->
      <div style="text-align: left">
        <span class="tit">比赛内容设置</span>
      </div>
      <!-- 关闭 -->
      <div class="closeWrapper" @click="ExitModel">
        <div class="i-1"></div>
        <div class="i-2"></div>
      </div>
      <!-- 选项卡 -->
      <Tabs @detailsMethod="detMet" :editModel="editModel" ref="TabsModel" @ok="ok" @del="del"></Tabs>
      <!-- 按钮 -->
      <div class="btnBox">
        <button class="btn-1" @click="SubmitBtn">确定</button>
        <!-- <button class="btn-2">增加</button> -->
        <button class="btn-3" @click="ResetBtn" v-if="delBtn">重置</button>
      </div>
    </div>
    <fromPopup ref="details" @PopupOne="WorkOne" @PopupTwo="WorkTwo" @PopupFusCali="WorkFusCali" @PopupLIDAR="WorkLIDAR" @PopupThree="WorkThree" @PopupFour="WorkFour">
    </fromPopup>
  </div>
</template>

<script>
import { defineComponent, toRaw } from "vue";
import fromPopup from "@/components/newIndexCopy/models/FromPopup.vue";
import { postData } from "@/assets/js/pubilcs.js";
import { ElMessage } from "element-plus";
// import Tabs from "@/components/newIndexCopy/models/Tabs.vue";
import Tabs from "@/components/newIndexCopy/models/FusCaliTabs.vue";
export default defineComponent({
  name: "",
  components: {
    Tabs,
    fromPopup,
  },
  props: {},
  data() {
    return {
      CreateMathBoolean: false,
      // CreateMathBoolean: true,
      model: [],
      // InstallConfig: {
      //   ShowName: false,
      //   ShowStep: false,
      //   ShowTip: false,
      // },
      // CalibrationConfig: {},
      FusionCalibrationConfig:[],
      LIDARConfig:{},
      ProtocolConfig: [],
      LaneDetectConfig: {},
      Product: {},
      editModel: "",
      delBtn: true,
    };
  },
  methods: {
    del() {
      this.delBtn = false;
    },
    edit(val) {
      this.editModel = val;
    },
    detMet(val) {
      this.$refs.details.show(val);
    },
    show(val) {
      this.Product = val;
      this.CreateMathBoolean = true;
    },
    ExitModel() {
      this.CreateMathBoolean = false;
      this.editModel = "";
    },
    ok(data) {
      console.log('okdata',data);
      this.model = data;
      // this.model[0].Settings = this.InstallConfig;
      // this.model[1].Settings = this.CalibrationConfig;
      // this.model[2].Settings = this.ProtocolConfig;
      // this.model[3].Settings = this.LaneDetectConfig;
      this.model.forEach((item, index) => {
        // if (item.Title == "项目一") {
        //   this.model[index].Settings = this.InstallConfig;
        // }
        // if (item.Title == "项目二") {
        //   this.model[index].Settings = this.CalibrationConfig;
        // }
        if (item.Title == "项目一") {
          this.model[index].Settings = this.FusionCalibrationConfig;
          console.log('this.FusionCalibrationConfig',this.FusionCalibrationConfig);
        }
        if (item.Title == "项目二") {
          this.model[index].Settings = this.LIDARConfig;
          console.log('this.LIDARConfig',this.LIDARConfig);
        }
        if (item.Title == "项目三") {
          this.model[index].Settings = this.ProtocolConfig;
        }
        if (item.Title == "项目四") {
          this.model[index].Settings = this.LaneDetectConfig;
        }
      });
      console.log(this.model.filter(Boolean));
      // if (this.model[0].Weight == null || this.model[0].Weight == "") {
      //   ElMessage ({
      //     message: "请完善内容设置",
      //     type: "warning",
      //   });
      //   return;
      // }
      // if (this.model[1].Weight == null || this.model[1].Weight == "") {
      //   ElMessage ({
      //     message: "请完善内容设置",
      //     type: "warning",
      //   });
      //   return;
      // }
      // if (this.model[2].Weight == null || this.model[2].Weight == "") {
      //   ElMessage ({
      //     message: "请完善内容设置",
      //     type: "warning",
      //   });
      //   return;
      // }
      // if (this.model[3].Weight == null || this.model[3].Weight == "") {
      //   ElMessage ({
      //     message: "请完善内容设置",
      //     type: "warning",
      //   });
      //   return;
      // }
      postData(
        "/api/SkillsContest/EditSCInformation",
        JSON.stringify({
          name: this.Product.name,
          startTime: this.Product.startTime,
          duration: this.Product.duration,
          content: JSON.stringify(this.model.filter(Boolean)),
          id: this.Product.id,
        }),
        sessionStorage.getItem("token")
      )
        .then((res) => {
          if (res.result.success) {
            console.log(res);
            ElMessage({
              message: "操作成功！",
              type: "success",
            });
            this.$emit("Resetlist");
            this.editModel = "";
            this.CreateMathBoolean = false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    SubmitBtn() {
      // this.Summary();
      // this.SummaruTwo();
      this.SummaryFusCali();
      this.SummaryLIDAR();
      this.SummaryThree();
      this.SummaryFour();
      this.$refs.TabsModel.ok();
    },
    // 数据汇总
    Summary() {
      this.InstallConfig.ShowName = false;
      this.InstallConfig.ShowStep = false;
      this.InstallConfig.ShowTip = false;
      if (JSON.parse(sessionStorage.getItem("EchoList"))) {
        if (JSON.parse(sessionStorage.getItem("EchoList"))[0] == 1) {
          this.InstallConfig.ShowName = true;
        }
      }

      if (JSON.parse(sessionStorage.getItem("EchoListTwo"))) {
        if (JSON.parse(sessionStorage.getItem("EchoListTwo"))[0] == 1) {
          this.InstallConfig.ShowStep = true;
          if (JSON.parse(sessionStorage.getItem("EchoListTwo"))[1] == 0) {
            this.InstallConfig.ShowTip = true;
          }
        }
        if (JSON.parse(sessionStorage.getItem("EchoListTwo"))[0] == 0) {
          this.InstallConfig.ShowTip = true;
        }
      }
    },
    SummaruTwo() {
      this.CalibrationConfig = JSON.parse(
        sessionStorage.getItem("CalibrationList")
      ) || { AxisCenter: 0, Position: [0, 0, 0], Angle: [0, 0, 0] };
    },
    SummaryFusCali() {
      this.FusionCalibrationConfig = JSON.parse(
        sessionStorage.getItem("FusionCalibrationList")
      ) || [1,3,8,12]
    },
    SummaryLIDAR(){
      this.LIDARConfig = JSON.parse(
        sessionStorage.getItem("LIDARList")
      ) || { MSOPPortValue:0,DIFOPPortValue:0,start:0,end:360,value:'300rmp/min' };
    },
    SummaryThree() {
      this.ProtocolConfig =
        JSON.parse(sessionStorage.getItem("AgreementList")) || [];
    },
    SummaryFour() {
      this.LaneDetectConfig = JSON.parse(
        sessionStorage.getItem("LaneDetectList")
      ) || { Id: 0 };
    },
    //详细设置传值
    WorkOne(data) {
      this.Summary();
      this.$refs.TabsModel.changeBtn(1);
      // this.InstallConfig = data;
    },
    WorkTwo(data) {
      this.SummaruTwo();
      this.$refs.TabsModel.changeBtn(2);
      // this.CalibrationConfig = data;
    },
    WorkFusCali(data) {
      this.SummaryFusCali();
      this.$refs.TabsModel.changeBtn(5);
      // this.InstallConfig = data;
    },
    WorkLIDAR(data) {
      this.SummaryLIDAR();
      this.$refs.TabsModel.changeBtn(6);
      // this.InstallConfig = data;
    },
    WorkThree(data) {
      this.SummaryThree();
      this.$refs.TabsModel.changeBtn(3);
      // this.ProtocolConfig = data;
    },
    WorkFour(data) {
      this.SummaryFour();
      this.$refs.TabsModel.changeBtn(4);
      // this.LaneDetectConfig = data;
    },
    // 重置
    ResetBtn() {
      this.$refs.TabsModel.Reset(9);
    },
  },
});
</script>

<style lang="less" scoped>
.wp {
  width: 100%;
  height: 100%;
  background-color: #00000033;
  position: absolute;
  left: 0;
  top: 0;
}

.content {
  position: absolute;
  overflow: hidden;
  top: 50%;
  left: 50%;
  width: 1396px;
  height: 780px;
  background: #ffffff;
  border-radius: 20px;
  transform: translate(-50%, -50%);
  padding: 20px 20px 0px 20px;
}

.tit {
  font-size: 24px;
  font-weight: 500;
  color: #81859c;
  line-height: 36px;
}

.closeWrapper {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  background: RGBA(230, 231, 235, 1);
  border-radius: 50%;
  z-index: 999;
}

.i-1,
.i-2 {
  position: absolute;
  left: 22%;
  top: 45%;
  width: 22px;
  height: 3px;
  border-radius: 2px;
  background-color: #81859c;
}

.i-1 {
  transform: rotate(45deg);
}

.i-2 {
  transform: rotate(-45deg);
}

.btnBox {
  margin: 0 auto;
}

.btnBox button {
  outline: none;
  border: none;
  width: 200px;
  height: 60px;
  font-size: 24px;
  border-radius: 10px;
  font-weight: 500;
  color: #ffffff;
  letter-spacing: 5px;
  margin-top: 50px;
}

.btn-1 {
  background: linear-gradient(270deg, #218cde 0%, #807de1 100%);
}

.btn-2,
.btn-3 {
  background: #81859c;
  margin-left: 60px;
}
</style>